<?php

if (!$l_loged) {
    include "login_error.php";
} else { if ($l_role < 0) {
        include "role_error.php";
    } else {
        ?>
<h2 class="cont_page">Editovat úkol</h2>
<?PHP
if (isset($_GET['btn']) && (($_GET['txt'] != '') && ($_GET['priorita'] != '') && ($_GET['splnit'] != ''))) {
    $date_parts = preg_split("/[.:,-]/", $_GET['splnit']);
    if (checkdate((int)$date_parts[1], (int)$date_parts[0], (int)$date_parts[2])){
        $ctrldate = (int)$date_parts[0].".".(int)$date_parts[1].".".(int)$date_parts[2];
        if ($ctrldate > date('d.m.Y')){
            if (task_upd($_GET['q'], $_GET['txt'],$_GET['priorita'], $ctrldate, $_GET['hotovo'])){
                echo('<p class="ok_desc">Úkol upraven..</p>');
            } else{
                echo('<p class="err_desc">Nezdařil se zápis do databáze..</p>');
            }
        }
    }
}

?>
<form action="task_edit.php" method="get" id="form_task">
    <fieldset  class="user">
        <legend>Nový úkol</legend>
        <p <?PHP if (isset($_GET['btn']) && ($_GET['txt'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="txt" class="nes">*Text:</label>
            <input maxlength="500" size="80" value="<?php echo htmlspecialchars($_GET['txt']);?>" type="text" id="txt" name="txt">
        </p>

        <p <?PHP if (isset($_GET['btn']) && ($_GET['priorita'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="priorita" class="nes">*Priorita: </label>
            <input maxlength="2" type="text" value="<?php echo htmlspecialchars($_GET['priorita']);?>" id="priorita" name="priorita"> 0-nizka, 99-nejvyšší
        </p>

        <p <?PHP if (isset($_GET['btn']) && ($_GET['splnit'] == '')) {echo ('class="err_form"');} else {echo ('class="ok_form"');} ?>>
            <label for="splnit" class="nes">*Splnit do: </label>
            <input type="text" maxlength="20" value="<?php if (isset($_GET['btn'])){echo htmlspecialchars($_GET['splnit']);} else {echo date('d.m.Y', strtotime('+1 month'));}?>" id="splnit" name="splnit"> ve formátu dd.mm.yyyy
        </p>
        <p class="ok_form">
            <label for="hotovo">Hotovo: </label>
            <input type="text" maxlength="100" value="<?php echo htmlspecialchars($_GET['hotovo']);?>" id="hotovo" name="hotovo"> %
        </p>

        <p class="inv">
            <input type="text" maxlength="10" value="<?php echo htmlspecialchars($_GET['q']);?>" id="q" name="q" >
        </p>
      <?PHP
      if (isset($_GET['btn']) && (($_GET['txt'] == '') || ($_GET['priorita'] == '') || ($_GET['splnit'] == ''))) {
          echo ('<p class="err_desc">* Všechny prvky touto barvou je nutné vyplnit!</p>');

          }
      if (isset($_GET['btn']) && ($_GET['splnit'] < date('d.m.Y'))){
          echo ('<p class="err_desc">Nelze zadat datum, které již bylo!</p>');
      }
      if (isset($_GET['btn'])){
        $date_part = preg_split("/[.:,-]/", $_GET['splnit']);
        if (!checkdate((int)$date_part[1], (int)$date_part[0], (int)$date_part[2])){
            echo ('<p class="err_desc">Datum neni ve spravnem tvaru!</p>');
        }
      }
      ?>

    <p>
        <input class="btn" type="submit" value="Zadat" id="btn" name="btn">
    </p>
    </fieldset>


</form>


<?php
}

}
?>
